"""
JsonWebToken | 模型
"""

from config import settings
from models import AnyTypeBase
from my_typing import *
from utils.data_utils.special import ObjectIdStr
from utils.validator_utils.pydantic_validator.field import (
    CharField,
    IntegerField,
    NormalField,
)


class JWTPayload(AnyTypeBase):
    """ JWT | 荷载 | Model  """

    expire_time: datetime = NormalField(..., title="过期时间")
    issue_time: datetime = NormalField(..., title="签发时间")
    subject: str = CharField(..., title="主题（Token 签发来源）")
    token_max_age: int = IntegerField(..., title="有效天数", min_value=1, max_value=30)
    user_id: ObjectIdStr = NormalField(..., title="用户 ID")

    def model_dump(self, **kwargs, ) -> dict[str, Any]:
        data = super().model_dump(**kwargs)
        data["expire_time"] = self.expire_time.strftime(settings.FORMAT.DATETIME_FORMAT)
        data["issue_time"] = self.issue_time.strftime(settings.FORMAT.DATETIME_FORMAT)

        return data
